(function( $, window ) {
  var Paginator = {
    category: 0,
    mediaKinds: [],
    onSelect: function(){},
    perpage: 20,

    update: function(total) {
      if (total <= 1) {
        this.clean();
        return;
      }
      $(".paginator").bootpag({total: total, maxVisible: 10});
    },

    clean: function() {
      $(".paginator ul").html("");
    },

    init: function(total, pagingFunc, default_page) {
      this.onSelect = pagingFunc;
      this._paginator(total, pagingFunc, default_page);
    },

    //helper
    _paginator: function(total, pagingFunc, default_page) {
      var default_page = default_page || 1;
      $('.paginator').bootpag({
        total: total,          // total pages
        page: default_page,            // default page
        maxVisible: 10,     // visible pagination
        leaps: true         // next/prev leaps through maxVisible
      }).on("page", function(event, num){
          pagingFunc(num);
      });
    }
  };


  window.Paginator = Paginator;

}( jQuery, window ));
